package com.ruoyi.project.search.viewOutHistory.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.search.viewOutHistory.domain.ViewOutHistory;
import com.ruoyi.project.search.viewOutHistory.service.IViewOutHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单据历史Controller
 * 
 * @author ruoyi
 * @date 2023-08-30
 */
@Controller
@RequestMapping("/search/viewOutHistory")
public class ViewOutHistoryController extends BaseController
{
    private String prefix = "search";

    @Autowired
    private IViewOutHistoryService viewOutHistoryService;

    @GetMapping()
    public String viewOutHistory()
    {
        return prefix + "/viewOutHistory";
    }

    /**
     * 查询出库单据历史列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewOutHistory viewOutHistory)
    {
        startPage();
        List<ViewOutHistory> list = viewOutHistoryService.selectViewOutHistoryList(viewOutHistory);
        return getDataTable(list);
    }

    /**
     * 导出出库单据历史列表
     */
    @Log(title = "出库单据历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewOutHistory viewOutHistory)
    {
        List<ViewOutHistory> list = viewOutHistoryService.selectViewOutHistoryList(viewOutHistory);
        ExcelUtil<ViewOutHistory> util = new ExcelUtil<ViewOutHistory>(ViewOutHistory.class);
        return util.exportExcel(list, "出库单据历史数据");
    }

    /**
     * 新增出库单据历史
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存出库单据历史
     */
    @Log(title = "出库单据历史", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewOutHistory viewOutHistory)
    {
        return toAjax(viewOutHistoryService.insertViewOutHistory(viewOutHistory));
    }

    /**
     * 修改出库单据历史
     */
    @GetMapping("/edit/{stockoutDetailId}")
    public String edit(@PathVariable("stockoutDetailId") String stockoutDetailId, ModelMap mmap)
    {
        ViewOutHistory viewOutHistory = viewOutHistoryService.selectViewOutHistoryByStockoutDetailId(stockoutDetailId);
        mmap.put("viewOutHistory", viewOutHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存出库单据历史
     */
    @Log(title = "出库单据历史", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewOutHistory viewOutHistory)
    {
        return toAjax(viewOutHistoryService.updateViewOutHistory(viewOutHistory));
    }

    /**
     * 删除出库单据历史
     */
    @Log(title = "出库单据历史", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewOutHistoryService.deleteViewOutHistoryByStockoutDetailIds(ids));
    }
}
